package com.ffapp.demo.common;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;


import com.ffapp.demo.bean.ProjectFileData;
import com.ffapp.demo.R;
import com.ffapp.demo.basis.BasisActivity;

import butterknife.BindView;
import butterknife.OnClick;

/***
 * 查看合同
 * **/
public class ViewFileDetailActivity extends BasisActivity {


    public  static void toDetail(Context context, ProjectFileData fileData){

        Intent intent = new Intent(context,ViewFileDetailActivity.class);
        Bundle extras = new Bundle();
        extras.putSerializable("data",fileData);
        extras.putString("title","");
        intent.putExtras(extras);
        context.startActivity(intent);
    }

    ProjectFileData mProjectFileData;

    @BindView(R.id.text_name)
    TextView text_name;

    @Override
    public void initViews() {
        // TODO Auto-generated method stub
        super.initViews();
        setContentView(R.layout.common_view_file_activity);
        setTitle("查看文件");
        setTitleLeftButton(null);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.initData(savedInstanceState);

        mProjectFileData = (ProjectFileData) getIntent().getSerializableExtra("data");

        if(mProjectFileData == null){
            showToast("文件不存在");
            finish();
            return;
        }
        String title = getIntent().getStringExtra("title");
        if(!TextUtils.isEmpty(title)){
            setTitle(title);
        }

        setView();
    }

    void setView(){
        if(mProjectFileData == null)return;
        ((ImageView)findViewById(R.id.img_icon)).setImageResource(mProjectFileData.getImgresByname());
        text_name.setText(mProjectFileData.getFileName());
    }

    @OnClick(R.id.btn_view_online)
    void viewOnline(){
        mProjectFileData.openOnline(mContext);
    }

    @OnClick(R.id.btn_download)
    void btnDownload(){
        mProjectFileData.saveToSD(mContext);
    }

}
